/*
 * ReciboForm.java
 *
 * Created on 12 de julio de 2008, 19:55
 */

package View;

import Controller.SegPedidoController;
import Model.Pedido;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import javax.swing.JFrame;
import javax.swing.JOptionPane;


/**
 *
 * @author  Gigin
 */
public class ReciboForm extends javax.swing.JDialog {
    private SegPedidoController mSegPedidoController;
    private Pedido mPedido;
    private SegPedidoForm mSegPedidoForm;
    
    /** Creates new form ReciboForm */
    public ReciboForm(java.awt.Frame parent, boolean modal, Pedido ped) {
        super(parent, modal);
        initComponents();
        mSegPedidoController = new SegPedidoController();
        this.mPedido = ped;
        this.mSegPedidoForm = (SegPedidoForm)parent;
        jLabelDeuda.setText("$ " + String.valueOf(ped.getTotal() - ped.getSenia()));
        jLabelCliente.setText(ped.getCliente().getApellidoCli() +", "+ped.getCliente().getNombreCli());
        jTextVuelto.setEnabled(false);
        
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jButtonImprimir = new javax.swing.JButton();
        jButtonAceptar = new javax.swing.JButton();
        jLabelDeuda = new javax.swing.JLabel();
        jButtonCancelar = new javax.swing.JButton();
        jLabel5 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabelCliente = new javax.swing.JLabel();
        jTextVuelto = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        jButtonCalcula = new javax.swing.JButton();
        jTextPagaCon = new javax.swing.JTextField();
        jLabelVuelto = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jLabel1.setFont(new java.awt.Font("Monotype Corsiva", 0, 24)); // NOI18N
        jLabel1.setForeground(new java.awt.Color(94, 148, 189));
        jLabel1.setText("Entregar Pedido");

        jLabel2.setFont(new java.awt.Font("Verdana", 1, 10));
        jLabel2.setText("DEUDA:");

        jButtonImprimir.setFont(new java.awt.Font("Verdana", 1, 10)); // NOI18N
        jButtonImprimir.setForeground(new java.awt.Color(94, 148, 189));
        jButtonImprimir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Botones/Imprimir_normal.gif"))); // NOI18N
        jButtonImprimir.setToolTipText("Imprimir recibo y aceptar pedido");
        jButtonImprimir.setBorderPainted(false);
        jButtonImprimir.setContentAreaFilled(false);
        jButtonImprimir.setDisabledIcon(new javax.swing.ImageIcon(getClass().getResource("/Botones/Imprimir_deshabilitado.gif"))); // NOI18N
        jButtonImprimir.setPressedIcon(new javax.swing.ImageIcon(getClass().getResource("/Botones/Imprimir_presionado.gif"))); // NOI18N
        jButtonImprimir.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/Botones/Imprimir_mouse.gif"))); // NOI18N
        jButtonImprimir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonImprimirActionPerformed(evt);
            }
        });

        jButtonAceptar.setFont(new java.awt.Font("Verdana", 1, 10));
        jButtonAceptar.setForeground(new java.awt.Color(94, 148, 189));
        jButtonAceptar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Botones/Aceptar_normal.gif"))); // NOI18N
        jButtonAceptar.setToolTipText("Entregar pedido");
        jButtonAceptar.setBorderPainted(false);
        jButtonAceptar.setContentAreaFilled(false);
        jButtonAceptar.setDisabledIcon(new javax.swing.ImageIcon(getClass().getResource("/Botones/Aceptar_deshabilitado.gif"))); // NOI18N
        jButtonAceptar.setFocusPainted(false);
        jButtonAceptar.setPressedIcon(new javax.swing.ImageIcon(getClass().getResource("/Botones/Aceptar_presionado.gif"))); // NOI18N
        jButtonAceptar.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/Botones/Aceptar_mouse.gif"))); // NOI18N
        jButtonAceptar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonAceptarActionPerformed(evt);
            }
        });

        jLabelDeuda.setFont(new java.awt.Font("Verdana", 0, 10));
        jLabelDeuda.setText("jLabel5");

        jButtonCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Botones/Cancelar_normal.gif"))); // NOI18N
        jButtonCancelar.setToolTipText("No entregar el pedido");
        jButtonCancelar.setBorderPainted(false);
        jButtonCancelar.setContentAreaFilled(false);
        jButtonCancelar.setDisabledIcon(new javax.swing.ImageIcon(getClass().getResource("/Botones/Cancelar_deshabilitado.gif"))); // NOI18N
        jButtonCancelar.setFocusPainted(false);
        jButtonCancelar.setPressedIcon(new javax.swing.ImageIcon(getClass().getResource("/Botones/Cancelar_presionado.gif"))); // NOI18N
        jButtonCancelar.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/Botones/Cancelar_mouse.gif"))); // NOI18N
        jButtonCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonCancelarActionPerformed(evt);
            }
        });

        jLabel5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Botones/logo_GTV4.gif"))); // NOI18N

        jLabel3.setFont(new java.awt.Font("Verdana", 1, 10));
        jLabel3.setText("CLIENTE:");

        jLabelCliente.setFont(new java.awt.Font("Verdana", 0, 10));
        jLabelCliente.setText("jLabel6");

        jTextVuelto.setFont(new java.awt.Font("Verdana", 0, 10)); // NOI18N

        jLabel7.setFont(new java.awt.Font("Verdana", 1, 10)); // NOI18N
        jLabel7.setText("Paga con: $");

        jButtonCalcula.setFont(new java.awt.Font("Tahoma", 1, 10)); // NOI18N
        jButtonCalcula.setForeground(new java.awt.Color(94, 148, 189));
        jButtonCalcula.setText("CALCULAR VUELTO");
        jButtonCalcula.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonCalculaActionPerformed(evt);
            }
        });

        jTextPagaCon.setFont(new java.awt.Font("Verdana", 0, 10)); // NOI18N

        jLabelVuelto.setFont(new java.awt.Font("Verdana", 1, 10)); // NOI18N
        jLabelVuelto.setText("Vuelto: $");

        jLabel4.setFont(new java.awt.Font("Verdana", 1, 10)); // NOI18N
        jLabel4.setForeground(new java.awt.Color(255, 0, 0));
        jLabel4.setText("El cliente debe cancelar la deuda");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(25, 25, 25)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(58, 58, 58)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(jLabel2)
                                    .addComponent(jLabel3)
                                    .addComponent(jLabel7))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jLabelDeuda)
                                            .addComponent(jLabelCliente))
                                        .addGap(117, 117, 117)
                                        .addComponent(jLabel5))
                                    .addComponent(jTextPagaCon, javax.swing.GroupLayout.PREFERRED_SIZE, 61, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jButtonAceptar, javax.swing.GroupLayout.PREFERRED_SIZE, 127, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jButtonImprimir, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(68, 68, 68)
                        .addComponent(jLabel1))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(83, 83, 83)
                        .addComponent(jButtonCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, 125, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(33, 33, 33)
                        .addComponent(jButtonCalcula, javax.swing.GroupLayout.PREFERRED_SIZE, 133, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jLabelVuelto)
                        .addGap(4, 4, 4)
                        .addComponent(jTextVuelto, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(97, 97, 97)
                        .addComponent(jLabel4)))
                .addContainerGap(30, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addGap(29, 29, 29)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel3)
                            .addComponent(jLabelCliente))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel2)
                            .addComponent(jLabelDeuda))
                        .addGap(32, 32, 32)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel7)
                            .addComponent(jTextPagaCon, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jButtonCalcula)
                            .addComponent(jLabelVuelto)
                            .addComponent(jTextVuelto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(jLabel5))
                .addGap(18, 18, 18)
                .addComponent(jLabel4)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 45, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButtonAceptar, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButtonImprimir, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(30, 30, 30)
                .addComponent(jButtonCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(33, 33, 33))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void jButtonImprimirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonImprimirActionPerformed
    SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd hh:mm:ss");
    Calendar calendar = Calendar.getInstance();
    
    mSegPedidoController.imprimirRecibo(String.valueOf(mPedido.getNroPedido()),
    mPedido.getCliente().getApellidoCli()+", "+mPedido.getCliente().getNombreCli(),
    format.format(calendar.getTime()), String.valueOf(mPedido.getTotal()),
    mPedido.getCongreso().getIniciales());
    
    
    mSegPedidoForm.aceptaEntrega();
      this.setVisible(false);
}//GEN-LAST:event_jButtonImprimirActionPerformed



private void jButtonAceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonAceptarActionPerformed
    mSegPedidoForm.aceptaEntrega();
    this.setVisible(false);
}//GEN-LAST:event_jButtonAceptarActionPerformed

private void jButtonCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCancelarActionPerformed
    
    this.setVisible(false);
}//GEN-LAST:event_jButtonCancelarActionPerformed

private void jButtonCalculaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCalculaActionPerformed
    
     float deuda = mPedido.getTotal() - mPedido.getSenia();
     try{
        float pagaCon =  Float.parseFloat(jTextPagaCon.getText());
        float vuelto = pagaCon - deuda;
        if(vuelto >= 0){
            
            jLabelVuelto.setVisible(true);
            jTextVuelto.setVisible(true);
            jTextVuelto.setText(String.valueOf(vuelto));
        }else{
            JOptionPane.showMessageDialog(new JFrame(), "El importe ingresado no cancela la deuda", "Atención!", JOptionPane.WARNING_MESSAGE);
        }
            
     }catch (Exception e){
     
     }
}//GEN-LAST:event_jButtonCalculaActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonAceptar;
    private javax.swing.JButton jButtonCalcula;
    private javax.swing.JButton jButtonCancelar;
    private javax.swing.JButton jButtonImprimir;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabelCliente;
    private javax.swing.JLabel jLabelDeuda;
    private javax.swing.JLabel jLabelVuelto;
    private javax.swing.JTextField jTextPagaCon;
    private javax.swing.JTextField jTextVuelto;
    // End of variables declaration//GEN-END:variables

}
